<template>
	<ui-radio-group
		v-model="innerValue"
	>
		<ui-radio
			v-for="(item, index) in options"
			:key="index"
			:value="item.value"
		>{{item.name}}</ui-radio>
	</ui-radio-group>
</template>

<script>
	export default {
		name: 'BiDynamicFormControlRadio',
		props: {
			/**
			 * {
			 * 		name: xxx,
			 * 		value: xxx
			 *	} 
			 */
			value: {
				type: Object
			},
			schema: {
				type: Object
			}
		},
		computed: {
			innerValue: {
				get () {
					let value
					if (this.value) {
						value = this.value.value
					}
					return value
				},
				set (val) {
					const option = this.options.find(v => v.value === val)
					if (option) {
						this.$emit('input', {
							value: option.value,
							name: option.name
						})
					} else {
						this.$emit('input', null)
					}
				}
			},
			options () {
				return this.schema.items || []
			}
		}
	}
</script>

<style>
</style>
